<template>
  <div>
    <el-card>
      <template #header>
        <div class="card-header">
          <span>库存管理</span>
          <el-button type="primary" @click="handleAdd">新增物料</el-button>
        </div>
      </template>
      
      <el-table :data="inventoryList" style="width: 100%">
        <el-table-column prop="code" label="物料编码" />
        <el-table-column prop="name" label="物料名称" />
        <el-table-column prop="specification" label="规格" />
        <el-table-column prop="category" label="分类" />
        <el-table-column prop="currentStock" label="当前库存" />
        <el-table-column prop="safeStock" label="安全库存" />
        <el-table-column prop="price" label="单价" />
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-button type="text" @click="handleEdit(row)">编辑</el-button>
            <el-button type="text" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { getInventoryList } from '@/utils/api'

const inventoryList = ref([])

const loadData = async () => {
  try {
    const res = await getInventoryList()
    inventoryList.value = res.data
  } catch (error) {
    console.error('加载数据失败:', error)
  }
}

const handleAdd = () => {
  // 添加物料逻辑
}

const handleEdit = (row) => {
  // 编辑物料逻辑
}

const handleDelete = (row) => {
  // 删除物料逻辑
}

onMounted(() => {
  loadData()
})
</script>
